// GlobalViewModelStore.java
package com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.utils;

import android.app.Application;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStore;

public class GlobalViewModelStore {
    private static GlobalViewModelStore instance;
    private final ViewModelProvider viewModelProvider;

    private GlobalViewModelStore(Application application) {
        viewModelProvider = new ViewModelProvider(
                new ViewModelStore(),
                GlobalViewModelFactory.getInstance(application)
        );
    }

    public static synchronized GlobalViewModelStore getInstance(Application application) {
        if (instance == null) {
            instance = new GlobalViewModelStore(application);
        }
        return instance;
    }

    public <T extends ViewModel> T get(Class<T> modelClass) {
        return viewModelProvider.get(modelClass);
    }
}